<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RoleRealm - 注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'PingFang SC', 'Inter', sans-serif;
            background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .header {
            padding: 20px 0;
            text-align: center;
        }

        .logo {
            color: white;
            font-size: 32px;
            font-weight: bold;
            margin-bottom: 8px;
        }

        .tagline {
            color: #e5e7eb;
            font-size: 16px;
        }

        .nav-links {
            margin-top: 20px;
        }

        .nav-links a {
            color: #e5e7eb;
            text-decoration: none;
            margin: 0 15px;
            font-size: 14px;
        }

        .nav-links a:hover {
            color: #f59e0b;
        }

        .main-content {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 40px 20px;
        }

        .register-container {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 40px;
            width: 100%;
            max-width: 450px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }

        .register-title {
            color: white;
            font-size: 28px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 30px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            color: #e5e7eb;
            font-size: 14px;
            margin-bottom: 8px;
            display: block;
        }

        .required {
            color: #ef4444;
        }

        .form-input {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.1);
            color: white;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        .form-input::placeholder {
            color: #9ca3af;
        }

        .form-input:focus {
            outline: none;
            border-color: #f59e0b;
            box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
        }

        .password-strength {
            margin-top: 8px;
            font-size: 12px;
        }

        .strength-bar {
            height: 4px;
            background: #e5e7eb;
            border-radius: 2px;
            margin-top: 4px;
            overflow: hidden;
        }

        .strength-fill {
            height: 100%;
            transition: all 0.3s ease;
            border-radius: 2px;
        }

        .strength-weak .strength-fill {
            width: 33%;
            background: #ef4444;
        }

        .strength-medium .strength-fill {
            width: 66%;
            background: #f59e0b;
        }

        .strength-strong .strength-fill {
            width: 100%;
            background: #10b981;
        }

        .agreement-group {
            display: flex;
            align-items: flex-start;
            gap: 10px;
            margin-bottom: 20px;
        }

        .agreement-checkbox {
            width: 18px;
            height: 18px;
            accent-color: #f59e0b;
            margin-top: 2px;
        }

        .agreement-text {
            color: #e5e7eb;
            font-size: 14px;
            line-height: 1.5;
        }

        .agreement-text a {
            color: #f59e0b;
            text-decoration: none;
        }

        .agreement-text a:hover {
            text-decoration: underline;
        }

        .register-btn {
            width: 100%;
            padding: 14px;
            background: #f59e0b;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-bottom: 20px;
        }

        .register-btn:hover {
            background: #d97706;
            transform: translateY(-2px);
        }

        .register-btn:active {
            transform: translateY(0);
        }

        .register-btn:disabled {
            background: #9ca3af;
            cursor: not-allowed;
            transform: none;
        }

        .login-link {
            text-align: center;
            color: #e5e7eb;
            font-size: 14px;
        }

        .login-link a {
            color: #f59e0b;
            text-decoration: none;
            font-weight: bold;
        }

        .footer {
            text-align: center;
            padding: 20px;
            color: #9ca3af;
            font-size: 14px;
        }

        .loading {
            display: none;
            text-align: center;
            color: #f59e0b;
            margin-top: 10px;
        }

        .spinner {
            border: 2px solid rgba(245, 158, 11, 0.3);
            border-top: 2px solid #f59e0b;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            animation: spin 1s linear infinite;
            display: inline-block;
            margin-right: 10px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .error-message {
            color: #ef4444;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }

        .success-message {
            color: #10b981;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }

        @media (max-width: 768px) {
            .register-container {
                margin: 20px;
                padding: 30px 20px;
            }
            
            .logo {
                font-size: 24px;
            }
            
            .tagline {
                font-size: 14px;
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <div class="logo">RoleRealm</div>
        <div class="tagline">与历史人物对话，体验沉浸式角色扮演</div>
        <nav class="nav-links">
            <a href="login.html">返回登录</a>
            <a href="#about">关于我们</a>
            <a href="#help">帮助</a>
        </nav>
    </header>

    <main class="main-content">
        <div class="register-container">
            <h1 class="register-title">注册账号</h1>
            <form id="registerForm">
                <div class="form-group">
                    <label class="form-label" for="username">用户名 <span class="required">*</span></label>
                    <input type="text" id="username" class="form-input" placeholder="请输入用户名" required>
                    <div class="error-message" id="usernameError"></div>
                </div>
                
                <div class="form-group">
                    <label class="form-label" for="email">邮箱 <span class="required">*</span></label>
                    <input type="email" id="email" class="form-input" placeholder="请输入邮箱地址" required>
                    <div class="error-message" id="emailError"></div>
                </div>
                
                <div class="form-group">
                    <label class="form-label" for="phone">手机号 <span class="required">*</span></label>
                    <input type="tel" id="phone" class="form-input" placeholder="请输入手机号" required>
                    <div class="error-message" id="phoneError"></div>
                </div>
                
                <div class="form-group">
                    <label class="form-label" for="password">密码 <span class="required">*</span></label>
                    <input type="password" id="password" class="form-input" placeholder="请输入密码" required>
                    <div class="password-strength" id="passwordStrength">
                        <div>密码强度：<span id="strengthText">弱</span></div>
                        <div class="strength-bar">
                            <div class="strength-fill"></div>
                        </div>
                    </div>
                    <div class="error-message" id="passwordError"></div>
                </div>
                
                <div class="form-group">
                    <label class="form-label" for="confirmPassword">确认密码 <span class="required">*</span></label>
                    <input type="password" id="confirmPassword" class="form-input" placeholder="请再次输入密码" required>
                    <div class="error-message" id="confirmPasswordError"></div>
                </div>
                
                <div class="agreement-group">
                    <input type="checkbox" id="agreement" class="agreement-checkbox" required>
                    <label for="agreement" class="agreement-text">
                        我已阅读并同意 <a href="#terms">用户协议</a> 和 <a href="#privacy">隐私政策</a>
                    </label>
                </div>
                
                <button type="submit" class="register-btn" id="registerBtn">注册</button>
                <div class="loading" id="loading">
                    <div class="spinner"></div>
                    正在注册...
                </div>
            </form>
            
            <div class="login-link">
                已有账号？<a href="login.html">立即登录</a>
            </div>
        </div>
    </main>

    <footer class="footer">
        技术支持：support@rolerealm.com
    </footer>

    <script>
        // 密码强度检测
        function checkPasswordStrength(password) {
            let strength = 0;
            const strengthBar = document.getElementById('passwordStrength');
            const strengthText = document.getElementById('strengthText');
            
            if (password.length >= 8) strength++;
            if (/[a-z]/.test(password)) strength++;
            if (/[A-Z]/.test(password)) strength++;
            if (/[0-9]/.test(password)) strength++;
            if (/[^A-Za-z0-9]/.test(password)) strength++;
            
            strengthBar.className = 'strength-bar';
            strengthText.textContent = '弱';
            
            if (strength >= 4) {
                strengthBar.className = 'strength-bar strength-strong';
                strengthText.textContent = '强';
            } else if (strength >= 2) {
                strengthBar.className = 'strength-bar strength-medium';
                strengthText.textContent = '中';
            } else {
                strengthBar.className = 'strength-bar strength-weak';
                strengthText.textContent = '弱';
            }
        }

        // 表单验证
        function validateForm() {
            let isValid = true;
            
            // 用户名验证
            const username = document.getElementById('username').value;
            const usernameError = document.getElementById('usernameError');
            if (!username) {
                usernameError.textContent = '请输入用户名';
                usernameError.style.display = 'block';
                isValid = false;
            } else if (username.length < 3) {
                usernameError.textContent = '用户名长度至少3位';
                usernameError.style.display = 'block';
                isValid = false;
            } else {
                usernameError.style.display = 'none';
            }
            
            // 邮箱验证
            const email = document.getElementById('email').value;
            const emailError = document.getElementById('emailError');
            if (!email) {
                emailError.textContent = '请输入邮箱';
                emailError.style.display = 'block';
                isValid = false;
            } else if (!/^[\w\.-]+@[\w\.-]+\.\w+$/.test(email)) {
                emailError.textContent = '请输入有效的邮箱地址';
                emailError.style.display = 'block';
                isValid = false;
            } else {
                emailError.style.display = 'none';
            }
            
            // 手机号验证
            const phone = document.getElementById('phone').value;
            const phoneError = document.getElementById('phoneError');
            if (!phone) {
                phoneError.textContent = '请输入手机号';
                phoneError.style.display = 'block';
                isValid = false;
            } else if (!/^1[3-9]\d{9}$/.test(phone)) {
                phoneError.textContent = '请输入有效的手机号';
                phoneError.style.display = 'block';
                isValid = false;
            } else {
                phoneError.style.display = 'none';
            }
            
            // 密码验证
            const password = document.getElementById('password').value;
            const passwordError = document.getElementById('passwordError');
            if (!password) {
                passwordError.textContent = '请输入密码';
                passwordError.style.display = 'block';
                isValid = false;
            } else if (password.length < 6) {
                passwordError.textContent = '密码长度至少6位';
                passwordError.style.display = 'block';
                isValid = false;
            } else {
                passwordError.style.display = 'none';
            }
            
            // 确认密码验证
            const confirmPassword = document.getElementById('confirmPassword').value;
            const confirmPasswordError = document.getElementById('confirmPasswordError');
            if (!confirmPassword) {
                confirmPasswordError.textContent = '请确认密码';
                confirmPasswordError.style.display = 'block';
                isValid = false;
            } else if (password !== confirmPassword) {
                confirmPasswordError.textContent = '两次输入的密码不一致';
                confirmPasswordError.style.display = 'block';
                isValid = false;
            } else {
                confirmPasswordError.style.display = 'none';
            }
            
            return isValid;
        }

        // 事件监听
        document.getElementById('password').addEventListener('input', function() {
            checkPasswordStrength(this.value);
        });

        document.getElementById('confirmPassword').addEventListener('input', function() {
            const password = document.getElementById('password').value;
            const confirmPassword = this.value;
            const error = document.getElementById('confirmPasswordError');
            
            if (confirmPassword && password !== confirmPassword) {
                error.textContent = '两次输入的密码不一致';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });

        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            if (!validateForm()) {
                return;
            }
            
            const registerBtn = document.getElementById('registerBtn');
            const loading = document.getElementById('loading');
            
            // 显示加载状态
            loading.style.display = 'block';
            registerBtn.style.display = 'none';
            registerBtn.disabled = true;
            
            // 模拟注册过程
            setTimeout(() => {
                loading.style.display = 'none';
                registerBtn.style.display = 'block';
                registerBtn.disabled = false;
                
                // 模拟注册成功，跳转到角色选择页面
                alert('注册成功！欢迎加入RoleRealm！');
                window.location.href = 'character-selection.html';
            }, 2000);
        });

        // 实时验证
        document.getElementById('username').addEventListener('blur', function() {
            const username = this.value;
            const error = document.getElementById('usernameError');
            
            if (username && username.length < 3) {
                error.textContent = '用户名长度至少3位';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });

        document.getElementById('email').addEventListener('blur', function() {
            const email = this.value;
            const error = document.getElementById('emailError');
            
            if (email && !/^[\w\.-]+@[\w\.-]+\.\w+$/.test(email)) {
                error.textContent = '请输入有效的邮箱地址';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });

        document.getElementById('phone').addEventListener('blur', function() {
            const phone = this.value;
            const error = document.getElementById('phoneError');
            
            if (phone && !/^1[3-9]\d{9}$/.test(phone)) {
                error.textContent = '请输入有效的手机号';
                error.style.display = 'block';
            } else {
                error.style.display = 'none';
            }
        });
    </script>
</body>
</html>
